home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / Booting Gallery / Booting Gallery (source) / (Libraries) / Sound Streaming / SoundSource.h < prev    next >
Encoding:
Text File  |  1996-06-22  |  2.2 KB  |  116 lines  |  [TEXT/BROW]

  1. // SoundSource.h
  2. // Created by Bill Hubauer on Fri, Jun 16, 1995 @ 7:33 AM.
  3.  
  4. #ifndef __SoundSource__
  5. #define __SoundSource__
  6.  
  7. #ifndef __MessageObjects__
  8. #include "MessageObjects.h"
  9. #endif
  10.  
  11. #ifndef __SOUND__
  12. #include <sound.h>
  13. #endif
  14.  
  15. #ifndef _OBJECTREF_
  16. #include "ObjectRef.h"
  17. #endif
  18.  
  19. #ifndef __SSTYPES__
  20. #include "SSTypes.h"
  21. #endif
  22.  
  23. #define    msgSSReadComplete        3000
  24.  
  25. class SSoundSource : public MMessageSender
  26. {
  27. public:
  28.     SSoundSource(UInt32    bufferSize);
  29.     virtual ~SSoundSource();
  30.     enum{errBufferNotReady = 1,errBufferBusy = 2};
  31.     
  32.     
  33.     virtual OSErr    GetSHeader(SHeader*& header) = 0;
  34.     UInt32            GetBufferSize()            {return _bufferSize;}
  35.     
  36.     void            SetAutoRefillQ(Boolean autoRefill)    {_autoRefillQ = autoRefill;}
  37.     
  38.     virtual    OSErr    Initialize();
  39.     
  40.         // this function will start an async buffer
  41.     virtual    OSErr    StartRead();
  42.             OSErr    GetBuffer(Ptr putItHere,UInt32&        theSize);
  43.             
  44.     virtual void    Reset()        {}
  45.  
  46. protected:
  47.             void    SendReadCompletion(UInt32 bytesRead,OSErr err)         {_bufferReadyQ = true;_sizeInBuffer = bytesRead;BroadcastMessage(msgSSReadComplete,&err);}
  48.     virtual    void    DoReadBuffer() = 0;    // this function fills the buffer can calls SendReadCompletion
  49.     
  50.     
  51.     Ptr        _buffer;
  52.     UInt32    _bufferSize;
  53.     UInt32    _sizeInBuffer;
  54.     Boolean    _autoRefillQ;
  55.     
  56.     Boolean    _bufferReadyQ;
  57.     
  58. };
  59.  
  60.  
  61. class CSoundInputDevice;
  62.  
  63. class SInputSource : public SSoundSource
  64. {
  65. public:
  66.     SInputSource(UInt32    bufferSize,OSType    quality);
  67.     virtual ~SInputSource();
  68.     
  69.     
  70.     virtual    OSErr    Initialize();
  71.     virtual OSErr    GetSHeader(SHeader*& header);
  72.  
  73. protected:
  74.     virtual    void    DoReadBuffer();
  75.     static pascal void _CompleteProc(OSErr    ioResult,UInt32 count,void* userData);
  76.     
  77. private:
  78.  
  79.     CSoundInputDevice*        _device;
  80.     OSType                    _quality;
  81.     
  82.     SHeader                    _curHeader;
  83.     
  84.  
  85. };
  86.  
  87.  
  88. DEFINE_REF(SSoundSource)
  89.  
  90.  
  91. class ResSoundSource : public SSoundSource
  92. {
  93. public:
  94.     ResSoundSource(UInt32 bufferSize,Handle lockedSndResource);
  95.     virtual ~ResSoundSource();
  96.  
  97.     virtual    OSErr    Initialize();
  98.     virtual OSErr    GetSHeader(SHeader*& header);
  99.     
  100.     virtual void    Reset()                {_pos = _startPos;_bytesToGo = _length;_bufferReadyQ = true;}
  101.  
  102. protected:
  103.  
  104.     virtual void    DoReadBuffer();
  105.  
  106.     Handle            _sndResource;
  107.     UInt32            _length;
  108.     UInt32            _bytesToGo;
  109.     Ptr                _startPos;
  110.     Ptr                _pos;
  111.  
  112. };
  113.  
  114.  
  115. #endif
  116.